//
//  UITextFieldAndTextViewViewController.swift
//  iOS-RxSwift-Tutorials_Example
//
//  Created by mengru.tian on 2020/9/20.
//  Copyright © 2020 CocoaPods. All rights reserved.
//

import UIKit

class UITextFieldAndTextViewViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!
    let array: [String] = [
        "20.1 监听单个 textField 内容的变化（textView 同理）"
        ,"20.2 将内容绑定到其他控件上"
        ,"20.3 同时监听多个 textField 内容的变化（textView 同理）"
        ,"20.4 事件监听"
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()

        title = "20.UI控件扩展2：UITextField、UITextView"
        view.backgroundColor = .white
    }
    
}
extension UITextFieldAndTextViewViewController: UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        switch indexPath.row {
        case 0:
            let vc = TextFieldTest1ViewController(nibName: "TextFieldTest1ViewController", bundle: nil)
            self.navigationController?.pushViewController(vc, animated: true)
            break
        case 1:
            let vc = TextFieldTest2ViewController(nibName: "TextFieldTest2ViewController", bundle: nil)
            self.navigationController?.pushViewController(vc, animated: true)
            break
        case 2:
            let vc = TextFieldTest3ViewController(nibName: "TextFieldTest3ViewController", bundle: nil)
            self.navigationController?.pushViewController(vc, animated: true)
            break
        case 3:
            let vc = TextFieldEventViewController(nibName: "TextFieldEventViewController", bundle: nil)
            self.navigationController?.pushViewController(vc, animated: true)
            break
        default:
            break
        }
    }
}

extension UITextFieldAndTextViewViewController: UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return array.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        if cell == nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
        }
        cell?.textLabel?.text = array[indexPath.row]
        return cell!
    }
}
